package com.hsh.dao.impl;

import com.hsh.bean.Courier;
import com.hsh.dao.CourierDao;
import com.hsh.util.DruidUtil;


import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.List;

public class CourierDaoImpl extends DruidUtil implements CourierDao {
    @Override
    public List<Courier> getCouriers() {
        List<Courier> couriers = new ArrayList<>();
        Connection conn = null;
        PreparedStatement state = null;
        ResultSet rs = null;
        try {
            conn = getConnection();
            String sql = "select * from courier";
            state =conn.prepareStatement(sql);
            rs = state.executeQuery();
            while(rs.next()){
                Courier courier = new Courier();
                courier.setCid(rs.getInt("cid"));
                courier.setUname(rs.getString("uname"));
                courier.setPassword(rs.getString("password"));
                courier.setNickname(rs.getString("nickname"));
                courier.setSex(rs.getString("sex"));
                courier.setPhone(rs.getString("phone"));
                couriers.add(courier);
            }
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            close(conn, state, rs);
        }
        return couriers;
    }
}
